<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>添加兑换商品</title>
<%@include file="../collect/meta.jsp"%>
<link rel="stylesheet" href="css/radius.css" type="text/css"></link>
<link rel="stylesheet" href="css/Inputstyle.css" type="text/css"></link>
<script type="text/javascript" src="${ctx}/js/returnTop.js"></script>
</head>
<body lang="zh-cn">
	<div class="wrapper">
		<c:import url="/collect/top.jsp"></c:import>
		<div class="main-container" id="main-container">
			<div class="main-container-inner">
				<c:import url="/collect/left.jsp"></c:import>
				<div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<ul class="breadcrumb">
							<li><i class="icon-home home-icon"></i>商品兑换</li>
							<li><a href="exchangegood!watchExgoods">兑换管理</a></li>
							<li>添加兑换商品</li>
						</ul>
						<!-- .breadcrumb -->
					</div>
					<div class="page-content">
						<div class="page-content-area">
							<div class="page-header">
								<h1>商品信息</h1>
							</div>
							<div class="row">
								<div class="col-xs-12">
									<form class="form-horizontal" name="addExchangeGoods"
										role="form" action="exchangegood!addExgood" method="post">
										<input type="hidden" id="eaId" name="exchangeGood.eaId"
											value="${exchangeGood.eaId }">
										<div id="table_bug_report">
											<div class="form-group">
												<label for="goodname" class="col-xs-2 col-sm-1 col-md-2"
													style="width:100px;">&nbsp商品名称:</label>
												<div class="col-xs-9 col-sm-6 col-md-10">
													<input type="text" class="form-control"
														style="width:200px;" name="exchangeGood.goodname"
														id="goodname">
												</div>
											</div>
											<div class="form-group">
												<label class="col-xs-2 col-sm-1 col-md-2"
													style="width:100px;">&nbsp店铺名称:</label>
												<div class="col-xs-9 col-sm-6 col-md-10">
													<select class="form-control" id="shopId" name="shopIds"
														multiple="multiple" style="height: 120px;width: 200px;">
														<c:forEach items="${shops}" var="shop">
															<option value="${shop.id }">${shop.name }</option>
														</c:forEach>
													</select>
													<p style="font-weight:bold;color:#0096BB;position:absolute;margin-left:210px;margin-top:-18px;">
														(按下Ctrl+鼠标左键可选择多个)
													</p>
												</div>
											</div>
											<div class="form-group">
												<label for="score" class="col-xs-2 col-sm-1 col-md-2"
													style="width:100px;">&nbsp兑换积分:</label>
												<div class="col-xs-9 col-sm-6 col-md-10">
													<input type="text" class="form-control"
														style="width:200px;" name="iscore" id="score">
												</div>
											</div>
											<div class="form-group">
												<label for="amount" class="col-xs-2 col-sm-1 col-md-2"
													style="width:100px;">&nbsp商品数量:</label>
												<div class="col-xs-9 col-sm-6 col-md-10">
													<input type="text" class="form-control"
														style="width:200px;" name="exchangeGood.amount"
														id="amount">
												</div>
											</div>
											<div class="form-group">
												<label for="exchangeAmount" class="col-xs-2 col-sm-1 col-md-2"
													style="width:100px;">&nbsp兑换次数:</label>
												<div class="col-xs-9 col-sm-6 col-md-10">
													<input type="text" class="form-control"
														style="width:200px;" name="exchangeGood.exchangeAmount"
														id="exchangeAmount">
													<p style="font-weight:bold;color:#0096BB;position:absolute;margin-left:210px;margin-top:-18px;">
														(兑换次数是指每个会员可兑换该商品的次数,不填写或填写0代表可无限次兑换)
													</p>
												</div>
											</div>
											<div class="clearfix">
												<div style="padding-left:100px;">
													<button class="btn btn-primary radius" type="button"
														onclick="sub();">确定</button>&nbsp;
													<a class="btn btn-primary radius"
														href="exchangegood!watchExgoods">返回</a>
												</div>
											</div>
										</div>
									</form>
								</div>
							</div>
							<!-- /.row -->
						</div>
						<!-- /.page-content-area -->
					</div>
					<!-- /.page-content-content -->
				</div>
				<!-- /.main-content -->
			</div>
			<!-- /.main-container-inner -->
			<a href="#" id="btn-scroll-up"
				class="btn-scroll-up btn btn-sm btn-inverse"
				style="position:fixed;bottom:0;"> <i
				class="icon-double-angle-up icon-only bigger-110"></i> </a>
		</div>
		<!-- /.main-container -->
		<div class="push"></div>
	</div>
	<c:import url="/collect/down.jsp"></c:import>
	<script type="text/javascript">
	function sub() {
		var goodname = document.getElementById("goodname").value;
		var score = document.getElementById("score").value;
		var amount = document.getElementById("amount").value;
		var exchangeAmount = document.getElementById("exchangeAmount").value;
		
		var flag = true;
		
		if (goodname.length == 0) {
			alert("请输入商品名称！");
			return false;
		}
		
		if ($("#shopId option:selected").length == 0) {
			alert("请选择店铺名称！");
			return false;
		}
		
		if (score.length == 0) {
			alert("请输入兑换积分！");
			return false;
		}
		if (!/^\d+$/.test(score)) {
			alert("兑换积分必须是正整数！");
			return false;
		}
		if (amount.length == 0) {
			alert("请输入商品数量！");
			return false;
		}
		if (!/^\d+$/.test(amount)) {
			alert("商品数量必须是正整数！");
			return false;
		}
		
		var eaId = $("#eaId").val();
		var shopIds = $("#shopId").val();
		$.ajax({
			async: false,
			url : "exchangegood!verifyGoodname",
			type: "post",
			data : {
				"goodname" : goodname,
				"eaId" : eaId,
				"shopIdArray" : shopIds.toString()
			},
			datatype : "json",
			success : function(data) {
				var map = eval("(" + data + ")");
				if (map != null) {
					flag = false;
					alert(map.temp);
				}
			},
			error : function(request) {
				flag = false;
				alert("Connection error");
			}
		});
		
		if (!/^\d+$/.test(exchangeAmount)) {
			$("#exchangeAmount").val("");
		}
		
		if (flag) {
			addExchangeGoods.submit();
		}
	}
	//防收回；$兑换管理
		$('.goodsexchange > ul').show();
		$('.goodsexchange > ul > li > a').eq(0).css("color","red");
	</script>
</body>
</html>